<extend name="./app/Tpl/Public/template.html" />
<block name="content_body">
	<div class="pad-lr-10">
		<form name="form_search" id="form_search" action="{:U('index')}" method="post">
		    <table width="100%" cellspacing="0" class="search-form">
		        <tbody>
		            <tr>
			            <td>
				            <div class="explain-col">							
								<select name="cate_id" style="width:250px;" class="chosen_search">
									<option value="">全部分类列表</option>
	                				<volist name="cateTree" id="val_1">
								    	<option value="{$val_1.id}"  <if condition="$val_1['id'] eq $cateId">selected</if>>{$val_1.code}-{$val_1.title}</option>
										<volist name="val_1['children']" id="val_2">
											<option value="{$val_2.id}"  <if condition="$val_2['id'] eq $cateId">selected</if>>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{$val_2.code}{$val_2.title}</option>								
										</volist>
	                				</volist>
								</select>
								<input type="button"  name="form_search_btn_search"  value="查询" onclick="document.forms['form_search'].submit()"/>
								<input type="button"  name="form_search_btn_addTop"  value="添加顶级分类" onclick="openDialogFormAdd('{:U('showAdd')}','0')"/>
								<input type="button"  name="form_search_btn_removeCache"  value="刷新缓存分类" onclick="removeCache()"/>		
				        	</div>
			            </td>
		            </tr>
		        </tbody>
		    </table>
	    </form>
	    <form  name="form_list" id="form_list" action="{:U('index')}" method="post">
	    	<input type="hidden" name="auth_type" value="group">
		    <div class="table-list">		
			    <table width="100%" cellspacing="0">
			        <thead>
			            <tr>
			            	<th width="50">ID</th> 
			            	<th width="50">选中</th>                 
			                <th>分类名称</th>
			      			<th width="100" align="left">排序</th>
			      			<th align="left">是否显示</th>
			      			<th align="left">操作</th>
			            </tr>
			        </thead>
			    	<tbody>
						<volist name="cateList" id='val'>
				        <tr class="{$val.cls} level_{$val.level}" iid="{$val.id}" pid="{$val.pid}" level="{$val.level}">
				        	<td align="center">{$val.id}</td>
				            <td align="center"><input type="checkbox" value="{$val.id}" name="id[]"></td>
				            <td align="left">
				            	<div style="margin-left:{$val['level']*30}px">
				            		
									<if condition="$val.level neq 3">
										<img src="__ROOT__/statics/images/tv-collapsable.gif" class="expandable" id="{$val.id}" pid="{$val.pid}" level="{$val.level}"/>	
									<else/>
									 	<img src="__ROOT__/statics/images/tv-expandable.gif" class="expandable" id="{$val.id}" pid="{$val.pid}" level="{$val.level}"/>						 
									</if>
				                    <span>{$val.code}-{$val.title}</span>
				                </div>            	
				           	</td>		
				            <td align="left">
				            	<input type="text" class="input-text-c input-text" value="{$val.ordlist}" size="4" name="ordlist[{$val.id}]" id="ordlist_{$val.id}" onblur="ordlist('{:U('ordlist')}',{$val.id},'ordlist',this.value)"  onkeyup="this.value=this.value.replace(/\D/g,'')" onafterpaste="this.value=this.value.replace(/\D/g,'')">
								<span id="ordlist_upd_{$val.id}" value="{$val.ordlist}"></span>
							</td>		
				            <td align="left" onclick="isShow('{:U('isShow')}','{$val.id}','is_show')" id="is_show_{$val.id}"><img src="__ROOT__/statics/images/is_show_{$val.is_show}.png" /></td>
				            <td align="left" class="btn">
				            		<a class="link_btn" href="javascript:openDialogFormUpd('{:U('showUpd')}','{$val.id}')" >编辑</a>
				            		<if condition="$val['level'] eq 1">
				            		<a class="link_btn" href="javascript:openDialogFormAdd('{:U('showAdd')}','{$val.id}')" >添加子菜单</a>
				            		</if>
				            </td>
				        </tr>
				        </volist>
			    	</tbody>
			    </table>
	
			    <div class="btn">
					<input type="button"  name="form_list_btn_ckAll" class="ckSelect" ck_type="all" ck_name="id[]" value="全选" />
					<input type="button"  name="form_list_btn_ckNone" class="ckSelect" ck_type="none"  ck_name="id[]" value="全不选" />
					<input type="button"  name="form_list_btn_ckReverse" class="ckSelect" ck_type="reverse" ck_name="id[]" value="反选"/>
					<input type="button"  name="form_list_btn_ckDel" value="删除选中项" onclick="doDel('{:U('doDel')}')"/>
					<div id="pages">{$page}</div>
			    </div>
	    	</div>
	    </form>
	</div>
	<div id="dialog_content" title="弹出框"></div>
<script type="text/javascript">

$(function(){
	//展开&收缩
	$('.expandable').toggle(
		function(){
			$('.pid_'+$(this).attr('id')).hide();		
			$(this).attr('src',ROOT_PATH+'/statics/images/tv-expandable.gif');
		},
		function(){
			$('.pid_'+$(this).attr('id')).show();
			$(this).attr('src',ROOT_PATH+'/statics/images/tv-collapsable.gif');
		}
	);
	//打开编辑窗口
	$( "#dialog_content" ).dialog({
		autoOpen: false,
		width:500,
		height:400
	});
})

//显示添加菜单窗口
function openDialogFormAdd(action_url,cate_pid){
	$.post(
		action_url, 
		{"cate_pid":cate_pid}, 
		function(htmldata){
			$("#dialog_content").dialog("option","title","添加新分类");
			$("#dialog_content").html(htmldata).dialog("open");
		},
		"html"
	);
}

//显示更新菜单窗口
function openDialogFormUpd(action_url,cate_id){
	$.post(
		action_url, 
		{"cate_id":cate_id}, 
		function(htmldata){
			$("#dialog_content").dialog("option","title","编辑分类");
			$("#dialog_content").html(htmldata).dialog("open");
		},
		"html"
	);
}

//删除操作
function doDel(action_url){
	if(confirm("确定删除选中项（如果选中项下有子菜单，会一同被删除）？")){
		$("#form_list").attr('action',action_url);
		$("#form_list").submit();
	}
	
}

//刷新菜单缓存文件
function removeCache(){
	$.get("{:U('removeCache')}", { }, function(jsondata){ 
		alert(jsondata);
	},'json'); 
}
</script>
</block>